import axios from 'axios';
// import {baseInfo} from "../common/config";
// import {getToken,removeToken,removeUsername,removeUserId} from "../common/storage";
let baseInfo = {
    baseURL: '',
    baseURLStorage: '',
    baseAdminUrl: ''
}
let baseURL = baseInfo.baseURL;
let baseURLStorage = baseInfo.baseURLStorage;
export {baseURL,baseURLStorage};
export function requestAdmin(config){
//   let Token = getToken();
  let Token = '';
  if(Token){
    config.headers={
      ...config.headers,
      'Token' : `${Token}`,
      'Authorization' : `token`,
    }
  }
  //使用axios创建公共的配置信息，不需要重复创建
  const instance = axios.create({
    baseURL:baseInfo.baseAdminUrl,
    headers:{...config.headers},
    timeout:100000
  });
  // axios请求拦截器 请求
  instance.interceptors.request.use(config=>{return config;})
  // axios响应拦截器 数据返回
  instance.interceptors.response.use(res=>{
    let {code,message} = res.data;
    //判断用户登录的token是否过期
    if(code === 1002){
    //   res.message = 'token过期，请重新登录';
    //   res.code = 1002;
    //   setTimeout(_ =>{
    //     removeToken();
    //     removeUsername();
    //     removeUserId();
    //   },1000);
    }
    if(message === "Expired token"){
    //   res.message = 'token过期，请重新登录';
    //   res.code = 1002;
    //   setTimeout(_ =>{
    //     removeToken();
    //     removeUsername();
    //     removeUserId();
    //   },1000);
    }
    return res;
  },err=>{
  })
  return instance(config);
}
